package com.aa.activity;

import com.aa.CallWaitActivity;
import com.aa.Common;
import com.aa.R;
import com.aa.contacts.KaguPhones;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class FirendInfoActivity extends Activity implements OnClickListener{

	private Button mbtnTitleBack;
	private TextView mtvTitleCenter;
	private ImageView mivHeadIcon;
	private TextView mtvPhoneNumber;
	private TextView mtvFirendName;
	private ImageButton mbtnUserIcon;
	private ImageButton mbtnAgentIcon;
	private TextView mtvSign;
	
	private ImageView mivRecommend;
	private ImageView mivPhoneCall;
	private ImageView mivSendSMS;
	private ImageView mivZhiCall;
	private ImageView mivCallBack;
	private KaguPhones mKaguPhones;
	private TextView mtvFirendArea;
	private TextView mtvFirendJop;
	private TextView mtvFirendBirthDay;
	private TextView mtvDream;
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.good_firend_info);
		
		mKaguPhones = (KaguPhones)getIntent().getSerializableExtra("KaguPhones"); 
		
		initView();
	}
	
	private void initView(){
		mbtnTitleBack = (Button)findViewById(R.id.btn_title_back);
		mbtnTitleBack.setOnClickListener(this);
		mtvTitleCenter = (TextView)findViewById(R.id.tv_title_center);
		mtvTitleCenter.setText(R.string.good_firend_info);
		
		mivHeadIcon = (ImageView)findViewById(R.id.iv_goodfirend_info_icon);
		mtvPhoneNumber = (TextView)findViewById(R.id.tv_goodfirend_info_phone);
		mtvPhoneNumber.setText(mKaguPhones.getPhoneNum());
		mtvFirendName = (TextView)findViewById(R.id.tv_goodfriend_info_name);
		mtvFirendName.setText(mKaguPhones.getDisplayName());
		mbtnUserIcon = (ImageButton)findViewById(R.id.btn_goodfriend_user_icon);
		if (mKaguPhones.getIsOnline() == 1) {
			mbtnUserIcon.setBackgroundResource(R.drawable.user_icon1);
		}
		mbtnAgentIcon = (ImageButton)findViewById(R.id.btn_goodfriend_agent_icon);
		
		if (mKaguPhones.getIsAgent() == 1) {
			mbtnAgentIcon.setVisibility(View.VISIBLE);
			if (mKaguPhones.getIsOnline() == 1) {
				mbtnAgentIcon.setBackgroundResource(R.drawable.agent_icon1);
			}
		}
		
		mtvSign = (TextView)findViewById(R.id.tv_goodfriend_info_sign);
		mtvSign.setText(mKaguPhones.getSign());
		mtvFirendArea = (TextView)findViewById(R.id.tv_goodfirend_info_area);
		mtvFirendArea.setText(mKaguPhones.getArea());
		mtvFirendBirthDay = (TextView)findViewById(R.id.tv_goodfirend_info_birth);
		mtvFirendBirthDay.setText(mKaguPhones.getBirthday());
		mtvFirendJop = (TextView)findViewById(R.id.tv_goodfirend_info_profession);
		mtvFirendJop.setText(mKaguPhones.getJop());
		mtvDream = (TextView)findViewById(R.id.tv_goodfirend_dream);
		mtvDream.setText(mKaguPhones.getDream());
		mivRecommend = (ImageView)findViewById(R.id.btn_goodfirend_info_recommend);
		if (Common.iAgentRank > 0) {
			if (mKaguPhones.getIsAgent() == 1) {
				mivRecommend.setVisibility(View.GONE);
			}
		}else if(Common.iAgentRank > 1){
			if (mKaguPhones.getIsAgent() == 0) {
				mivRecommend.setVisibility(View.GONE);
			}
		}
		
		
		
		mivPhoneCall = (ImageView)findViewById(R.id.btn_goodfirend_info_phonecall);
		mivSendSMS = (ImageView)findViewById(R.id.btn_goodfirend_info_sendsms);
		mivZhiCall = (ImageView)findViewById(R.id.btn_goodfirend_info_zhicall);
		mivCallBack = (ImageView)findViewById(R.id.btn_goodfirend_info_callback);
		
		mivRecommend.setOnClickListener(this);
		mivPhoneCall.setOnClickListener(this);
		mivSendSMS.setOnClickListener(this);
		mivZhiCall.setOnClickListener(this);
		mivCallBack.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_back:
			finish();
			break;
		case R.id.btn_goodfirend_info_recommend:
			Intent _Intent3 = new Intent(FirendInfoActivity.this, FirendACommendctivity.class);
			Bundle _Bundle = new Bundle();
			_Bundle.putString("PHONE", mKaguPhones.getPhoneNum());
			if (mKaguPhones.getIsAgent() == 1) {
				_Bundle.putInt("TYPE", 3);
			}else {
				_Bundle.putInt("TYPE", 4);
			}
			_Intent3.putExtras(_Bundle);
			startActivity(_Intent3);
			
			break;
		case R.id.btn_goodfirend_info_phonecall:
			Intent _Intent = new Intent();
		    _Intent.setAction("android.intent.action.CALL");
		    _Intent.setData(Uri.parse("tel:" + mKaguPhones.getPhoneNum()));
		    startActivity(_Intent);
			break;
		case R.id.btn_goodfirend_info_sendsms:
	
			break;
		case R.id.btn_goodfirend_info_zhicall:
	
			break;
		case R.id.btn_goodfirend_info_callback:
			 if( mKaguPhones.getPhoneNum().equals(getString(R.string.number_private))){
			    	
			      String str = getString(R.string.app_net_tip1);
			      Toast.makeText(FirendInfoActivity.this, str, 3000).show();
			      return;
			    }
			    Common.iCallName = mKaguPhones.getDisplayName();
			    String _PhoneNum = mKaguPhones.getPhoneNum();
			    if (_PhoneNum.startsWith("+86")) {
			    	Common.iCallNumber = _PhoneNum.substring(3, _PhoneNum.length());
				}else {
					 Common.iCallNumber = _PhoneNum;
				}
			
			Intent _Intent2 = new Intent();
			_Intent2.setClass(FirendInfoActivity.this, CallWaitActivity.class);
			startActivity(_Intent2);
			break;

		}
		
	}
	
	
	
}
